package com.gitee.swsk33.algorithms.tree.huffmancode;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 赫夫曼编码测试
 */
public class HuffmanCodeTest {

	public static void main(String[] args) {
		// 构造赫夫曼树
		TreeNode node1 = new TreeNode('A', 17, null, null, null);
		TreeNode node2 = new TreeNode('B', 2, null, null, null);
		TreeNode node3 = new TreeNode('C', 49, null, null, null);
		TreeNode node4 = new TreeNode('D', 11, null, null, null);
		TreeNode node5 = new TreeNode('E', 5, null, null, null);
		TreeNode node6 = new TreeNode('F', 16, null, null, null);
		List<TreeNode> nodes = new ArrayList<>();
		nodes.add(node1);
		nodes.add(node2);
		nodes.add(node3);
		nodes.add(node4);
		nodes.add(node5);
		nodes.add(node6);
		HuffmanTreeCode treeCode = new HuffmanTreeCode(nodes);
		// 获取编码
		Map<Character, String> codes = treeCode.getAllCharCode();
		// 输出看看
		for (char key : codes.keySet()) {
			System.out.println("字符：" + key + " 编码：" + codes.get(key));
		}
	}

}